/**
 * Copyright (C), 2018-2018
 * FileName: BookService  * Author:   lcsos
 * Date:     2018/10/7 10:12
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.spring.rabbitmq.service;

import com.spring.rabbitmq.bean.Book;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * 〈一句话功能简述〉<br>  
 * 监听来自消息队列里面Book相关的内容
 *
 * @author Lcs
 * @create 2018/10/7 
 * @since 1.0.0
 */

@Service
public class BookService {
    //监听RabbitMQ,具体到哪一个队列,需要在Application.java中开启基于Rabbit注解的模式
    @RabbitListener(queues = "lcs.news")
    public void recive(Book book){
        System.out.println("收到的消息："+book);
    }

    //Message是org.springframework.amqp.core.Message
    @RabbitListener(queues = "lcs")//监听消息头
    public void recive0(Message message){
        System.out.println(message.getBody());//消息的内容
        System.out.println(message.getMessageProperties());//消息头信息
    }
}
